package com.example.springinterceptor.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2023/5/7 15:50
 */
@Configuration
public class AppConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/**/user/login")
                .excludePathPatterns("/**/user/res")
                .excludePathPatterns("/**/*.html")
                .excludePathPatterns("/**/getnum")
                .excludePathPatterns("/**/getstr");
    }

//    @Override
//    public void configurePathMatch(PathMatchConfigurer configurer) {
//        //方法一 ：在实现WebMvcConfigurer接口的类中 重写 configurePathMatch方法，调用 addPathPrefix 设置
//        configurer.addPathPrefix("/nb",c->true);
//    }
}
